<template>
	<view>
	<u-toast ref="uToast"></u-toast>
		<modal v-if="show" title="上数" confirm-text="确定" cancel-text="取消" @cancel="cancelPop" @confirm="confirmPop">
			<input v-model="num" type='number' placeholder="请输入上数数量" />
		</modal>


		<view class="top">


			<view class="item" @click="scanCode">
				<view class="">
					<image style="width: 80rpx;height: 80rpx;" src="../../static/sys.png" mode=""></image>
					<view>
						扫一扫
					</view>
				</view>
				
			</view>

			<view class="item" @click="ss()">
				<view class="">
					<image style="width: 85rpx;height: 85rpx;" src="../../static/ss.png" mode=""></image>
					<view>
						搜一搜
					</view>
				</view>
				
			</view>
		</view>


		<view class="content">


			<view class="son">
				菲码编号:{{data.id}}
			</view>
			
			<view class="son">
				款式:{{data.clothesName}} 款式编号:{{data.clothesEncode}}
			</view>
			<view class="son">
				时间批次:{{data.createTime}}
			</view>

			<view class="detail">
				<view class="info">
					颜色:{{data.colorName}}
				</view>

				<view class="info">
					尺码:{{data.sizeName}}
				</view>

				<view class="info">
					计划生产数量:{{data.mount}}件
				</view>
			</view>
		</view>

		<u-divider text="工序" :hairline="true"></u-divider>
		<view class="">
			<u-cell title="整件生产"  center>
				<template slot='label'>
					{{info}}
				</template>

             
				<button v-show="!chShow" slot="value" class="u-slot-value" @click="send">上传</button>
				<button   v-show="chShow" slot="value" class="u-slot-value" @click="del">撤回</button>
			</u-cell>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				alnum:0,
				id:"",//上传任务id
				info:"暂未上传",
				chShow:false,
				num: "",//上数的数量
				show: false,
				taskId: "",//非码id
				companyId:"",//自己公司id
				employeeId:"",//员工id
				data: {}, //查询到的衣服详情数据
			}
		},
		methods: {
			scanCode() {
				var that = this
				// 允许从相机和相册扫码
				uni.scanCode({
					scanType: ["qrCode"],
					success: (res) => {
						console.log(res);
						if (res.result) {
							const val = res.result;
				            that.taskId=res.result
							this.api.get("/clothes/selectClothesTaskById/" + res.result, {}).then(res => {
								that.data = res.data
								console.log(res);
								 that.getMyTask()
							})
							        
							
							
						} else {
			
							console.log('请重新扫描');
							that.$refs.uToast.show({
								type: 'error',
								icon: false,
								title: '提示',
								message: "请重新扫描",
								iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png'
							})
							return false;
						}
					},
					fail: (res) => {
						that.$refs.uToast.show({
							type: 'error',
							icon: false,
							title: '提示',
							message: "未识别到二维码",
							iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png'
						})
						console.log('未识别到二维码');
					}
				})
			},
			del(){
				var that = this
				this.api.post("/clothes/delTaskMount/",{
					id:that.id,
					taskId:that.taskId,
					num:that.alnum
				}).then(res => {
					that.getMyTask()
					console.log(res);
				})
			},
			getClothes(){
				
			},
			getMyTask(){
			
				var that = this
				this.api.post("/clothes/showTaskMount/", {
					employeeId:that.$store.state.employeeId,
					companyId:that.$store.state.myCompanyId,
					taskId:that.taskId,
				}).then(res => {
					console.log(res);
					if(res.data!=null){
						that.id=res.data.id
						that.chShow=true
						that.info="已上数"+res.data.num+"件 "+ res.data.recordTime
						that.alnum=res.data.num
					}else{
						that.chShow=false
						that.info="暂未上传"
					}
				
				})
			},
			ss() {
				uni.navigateTo({
					url: "/pages/artificial/artificial"
				})
			},
			send() {
				this.show = true
			},
			//弹窗
			confirmPop() { //确认
			if(this.num==""){
				console.log('请重新扫描');
				this.$refs.uToast.show({
					type: 'error',
					icon: false,
					title: '提示',
					message: "请输入上数数量",
					iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png'
				})
				return
			}
			console.log('点击了确定')
			this.show = false
			var that = this
			this.api.post("/clothes/addTaskMount/",{
				num:that.num,
				employeeId:that.$store.state.employeeId,
				companyId:that.$store.state.myCompanyId,
				taskId:that.taskId,
			}).then(res => {
				that.getMyTask()
				that.num=""
				console.log(res);
			})
			
			

		
				
			},
			cancelPop() { //取消
				console.log('点击了取消')
				this.show = false
			},

		},
		onLoad: function(options) {
			console.log(options)
			this.taskId = options.taskId
			var that = this
			this.api.get("/clothes/selectClothesTaskById/" + this.taskId, {}).then(res => {
				that.data = res.data
				console.log(res);
			})
        
             this.getMyTask()

		},
	}
</script>

<style>
	.top {
		display: flex;
		justify-content: space-between;
      width: 100%;
	}

	.info {
		padding-right: 20rpx;
	}

	.son {
		margin: 20rpx;
	}

	.content {
		background-color: #eceeef;
	}

	.detail {

		display: flex;
		margin: 20rpx;
	}

	.item {
		background-color: #FFFFFF;
		padding: 20rpx;
		border-radius: 15rpx;
		margin: 20rpx;
		width: 49%;
		
		 display:flex;
		
		        flex-deriction:row/column;
		
		        justify-content:center;
		
		        align-item:center;
	}
</style>
